package leetcode_top;

import java.util.*;
import org.junit.*;
public class Ex171 {
    class Solution {
        public int titleToNumber(String columnTitle) {
            int len;
            if (columnTitle == null || 
                (len = columnTitle.length()) == 0)
                 return 0;

            Map<Character, Integer> map = new HashMap<>();
            for (int i = 0; i < 26; i++) {
                map.put((char)('A' + i), i + 1);
            }
            
            char[] cs = columnTitle.toCharArray();
            int res = 0;
            for (int i = len - 1; i >= 0; i--) {
                res += map.get(cs[i]) * (int)Math.pow(26, len - i - 1);
            }
            return res;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        System.out.println(s.titleToNumber("ZY"));        
    }
}
